Skip to content

Added ASN.1 UPER and OER encoding#5031

Open
polybassa wants to merge 15 commits into
secdev:masterfrom
polybassa:v2x
Open

Added ASN.1 UPER and OER encoding#5031
polybassa wants to merge 15 commits into
secdev:masterfrom
polybassa:v2x

Conversation

@polybassa

Copy link
Copy Markdown
Contributor

This encoders are a preparation to support V2X / C-ITS communication in Scapy.

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.87492% with 177 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.47%. Comparing base (de33992) to head (fc870e9).

Files with missing lines Patch % Lines
scapy/asn1/uper.py 89.15% 78 Missing ⚠️
scapy/asn1/oer.py 87.73% 53 Missing ⚠️
scapy/asn1fields.py 89.40% 46 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5031      +/-   ##
==========================================
+ Coverage   80.13%   80.47%   +0.33%     
==========================================
  Files         388      390       +2     
  Lines       96467    97990    +1523     
==========================================
+ Hits        77308    78854    +1546     
+ Misses      19159    19136      -23     
Files with missing lines Coverage Δ
scapy/all.py 100.00% <100.00%> (ø)
scapy/asn1/ber.py 96.62% <100.00%> (+13.90%) ⬆️
scapy/asn1fields.py 92.52% <89.40%> (+8.88%) ⬆️
scapy/asn1/oer.py 87.73% <87.73%> (ø)
scapy/asn1/uper.py 89.15% <89.15%> (ø)

... and 13 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread .config/ci/install.ps1 Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces ASN.1 UPER (Unaligned PER) and OER (Octet Encoding Rules) support in Scapy as groundwork for V2X / C-ITS, along with a broad set of interoperability, roundtrip, dissection, and fuzzing tests to validate the new encoders/decoders.

Changes:

  • Add an OER codec implementation and expose OER/UPER via scapy.all.
  • Extend asn1fields to support OER/PER-specific encoding/decoding behaviors (tagging, PER presence bits, constrained sizes/ranges, etc.).
  • Add extensive UPER/OER test vectors, interoperability checks, fuzz tests, and cross-codec build/dissect coverage.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
scapy/asn1/oer.py New OER codec implementation (lengths, integers, strings, tags, primitives).
scapy/asn1fields.py Adds OER/PER-aware field encoding/decoding and PER decoder-path support for SEQUENCE/CHOICE/SEQUENCE OF.
scapy/asn1/ber.py Uses configured default long-form sizing for explicit tags and SEQUENCE length encoding.
scapy/all.py Exposes OER/UPER APIs via scapy.all.
test/scapy/layers/uper_packets.py UPER packet/field build+roundtrip tests with fixed vectors.
test/scapy/layers/uper_codec.py UPER primitive codec roundtrips + reference encode/decode vectors.
test/scapy/layers/uper_helpers.py UPER low-level helper/bitstream tests (length determinant, constrained ints, etc.).
test/scapy/layers/uper_iop.py UPER interoperability vectors vs reference encodings (asn1tools-derived).
test/scapy/layers/uper_asn1scc_iop.py UPER interoperability vectors derived from ESA asn1scc test cases.
test/scapy/layers/uper_fuzz.py UPER fuzz tests for packet and codec decode robustness.
test/scapy/layers/oer_packets.py OER packet/field build+roundtrip tests with fixed vectors.
test/scapy/layers/oer_iop.py OER interoperability vectors vs reference encodings (asn1tools-derived).
test/scapy/layers/oer_fuzz.py OER fuzz tests for packet and codec decode robustness.
test/scapy/layers/ber_packets.py BER packet/field build+roundtrip tests used for cross-codec parity coverage.
test/scapy/layers/ber_codec.py BER helper/codec coverage tests (tagging, len/num/id, primitive codecs).
test/scapy/layers/asn1_build_tests.py Cross-codec (BER/OER/PER) build and roundtrip tests.
test/scapy/layers/asn1_dissect_tests.py Cross-codec dissection tests from fixed byte vectors.
test/scapy/layers/asn1_coverage.py Additional coverage for UPER/OER and new asn1fields behaviors.
test/scapy/layers/asn1.uts Wires new UPER/OER/BER tests into the UTS test suite.
.config/codespell_ignore.txt Adds common ASN.1/per-related terms to codespell ignore list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scapy/asn1fields.py Outdated
Comment thread scapy/asn1fields.py Outdated
Nils Weiss added 14 commits July 14, 2026 21:11
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Sonnet 5)
OER SEQUENCE and SEQUENCE OF fields now propagate unconsumed bytes to
their parent instead of raising, enabling nested structures and fields
that follow a sequence within an enclosing SEQUENCE.

AI-Assisted: yes (Cursor AI)
Use a valid --after date so the AI-Assisted trailer check runs, and route
ASN1F_PACKET encode/decode through OER tagging like other ASN.1 fields.

AI-Assisted: yes (Cursor AI)
AI-Assisted: no

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.

Comment thread scapy/asn1fields.py
Comment on lines +360 to +368
codec = self.ASN1_tag.get_codec(pkt.ASN1_codec)
size_len = self.size_len or 0
if pkt.ASN1_codec == ASN1_Codecs.OER and self.oer_unsigned:
return codec.enc(
item, size_len=size_len, oer_unsigned=True
) # type: ignore[call-arg]
if pkt.ASN1_codec == ASN1_Codecs.PER:
return codec.enc(item, **self._uper_codec_kwargs(size_len))
return codec.enc(item, size_len=size_len)
Comment thread scapy/asn1fields.py
Comment on lines +1084 to +1091
def is_empty(self, pkt):
# type: (ASN1_Packet) -> bool
val = getattr(pkt, self._field.name, None)
if val is None:
return True
if getattr(self._field, "islist", 0) and val == []:
return True
return False
Comment thread scapy/asn1/oer.py
Comment on lines +321 to +336
real_tag = None
if explicit_tag is not None and len(s) > 0:
err_msg = (
"OER_tagging_dec: observed tag 0x%.02x does not "
"match expected tag 0x%.02x (%s)"
)
tag_class, tag_number, remainder = OER_tag_dec(s)
observed = tag_class | tag_number
if observed != explicit_tag:
if not safe:
raise OER_Decoding_Error(
err_msg % (observed, explicit_tag, _fname),
remaining=s)
real_tag = observed
s = remainder
return real_tag, s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants